package algorithm;

public class leetcode_0028 {
    public int strStr(String haystack, String needle) {
        if(needle.equals("")) return 0;
        if(haystack.equals("")) return -1;
        char[] list1=haystack.toCharArray();
        char[] list2=needle.toCharArray();
        int len1=list1.length;
        int len2=list2.length;
        for(int i=0;i<len1;++i){
            if(list1[i]==list2[0]&&i+len2<=len1){
                int j;
                for(j=0;j<len2;++j){
                    if(list1[i+j]!=list2[j]) break;
                }
                if(j==len2) return i;
            }
        }
        return -1;
    }
}
